<?php
include $_SERVER['DOCUMENT_ROOT'] . '/quocha/lib/Sanpham.php';
$sanphamOb = new Sanpham();
//Xu ly them xoa
$command = '';
$id = '';
$message = array();
if (isset($_GET['command'])) {
    $command = $_GET['command'];
}
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
if ($command == 'del') {
    if ($sanphamOb->xoaSanPham($id)) {
        $message[] = "Xóa thành công";
    } else {
        $message[] = "Xóa thất bại";
    }
}
$dsSanpham = $sanphamOb->layDanhSachSanPham();
//-------------------
$dsSanpham = $sanphamOb->layDSSP();
?>

<div class="grid_10">
    <div class="box round first grid">

        <?php foreach ($message as $mes): ?>
            <div class="message success">
                <p><?php echo $mes; ?></p>
            </div>
        <?php endforeach; ?>

        <h2>Quản lý sản phẩm
        </h2>
       <a href="/quocha/admin/capnhatsanpham.php">Thêm</a>
        <div class="block">

            <table class="data display datatable" id="example">
                <div class="command_area">

                </div>
                <thead>
                    <tr>
                        <th>Tên sản phẩm</th>
                        <th>Tiêu đề</th>
                        <th>Giá</th>
                        <th>Đặc biệt</th>
                        <th>Size</th>
                        <th>Chất liệu</th>
                        <th>Màu</th>
                        <th>Trạng thái</th>
                        <th></th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($dsSanpham as $sanpham): ?>
                        <tr class="odd gradeX">
                            <td><?php echo $sanpham['ten'] ?></td>
                            <td><?php echo $sanpham['tieude'] ?></td>
                            <td><?php echo $sanpham['gia'] ?></td>
                            <td><?php echo $sanpham['dacbiet'] ?></td>
                            <td><?php echo $sanpham['size'] ?></td>
                            <td><?php echo $sanpham['chatlieu'] ?></td>
                            <td><?php echo $sanpham['mau'] ?></td>
                            <td><?php echo $sanpham['trangthai'] ?></td>
                            <td class="center"><?php echo "<a href='/quocha/admin/sanpham.php?command=del&id=" . $sanpham['id'] . "'>Xóa"; ?></td>
                            <td class="center"><?php echo "<a href='/quocha/admin/capnhatsanpham.php?command=edit&id=" . $sanpham['id'] . "'>Sửa"; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
